************************************
*for analysis, open allvotes050512 data
use "allvotes050512.dta", clear

*set data for cox models
stset t1, failure(outcome) time(t0)

************DESCRIPTIVES TABLE 2
tab leaderposition if debatelevel==1
tab leaderposition if debatelevel==0
tab chairman if debatelevel==1
tab chairman if debatelevel==0
tab committee if debatelevel==1
tab committee if debatelevel==0
tab party if debatelevel==1
tab party if debatelevel==0
tab reelection if debatelevel==1
tab reelection if debatelevel==0
tab senior if debatelevel==1
tab senior if debatelevel==0
tab amendcosponsor if debatelevel==1
tab amendcosponsor if debatelevel==0
tab respeak if debatelevel==1
tab respeak if debatelevel==0
tab yea_nay if debatelevel==1
tab yea_nay if debatelevel==0
tab respeak if debatelevel==1
tab respeak if debatelevel==0


sum absnom if debatelevel==1
sum absnom if debatelevel==0
sum rawc if debatelevel==1
sum rawc if debatelevel==0
sum office if debatelevel==1
sum office if debatelevel==0
sum busy if debatelevel==1
sum busy if debatelevel==0
sum number_o if debatelevel==1
sum number_o if debatelevel==0


*general pooled model excluding closeness of vote but including debated level
*this is the model used in the paper, in Table 4
stcox leaderposition chairman committee absnom party reelection ///
number_o senior rawcscor amendcosponsor busy office hr1904 s1 ///
s445 respeak debatelevel, nohr cluster(name) strata(state) efron schoenfeld(sch*) scaledsch(sca*)
stphtest, rank detail
drop sch1-sca17

*generate prop. hazards interaction - note, debatet is not used here
gen respeakt=respeak*ln(t1)
gen debatet=debatelevel*ln(t1)

*model reported in Table 4 after correcting for prop. hazards violation
stcox leaderposition chairman committee absnom party reelection ///
number_o senior rawcscor amendcosponsor busy office hr1904 s1 ///
s445 respeak debatelevel hr1904t s1t s445t debatet, nohr cluster(name) strata(state) efron

*above model with hazard ratios
stcox leaderposition chairman committee absnom party reelection ///
number_o senior rawcscor amendcosponsor busy office hr1904 s1 ///
s445 respeak debatelevel hr1904t s1t s445t debatet, cluster(name) strata(state) efron

*model with debated*leader, also used in Table 4
stcox leaderposition chairman committee absnom party reelection ///
number_o senior rawcscor amendcosponsor busy office hr1904 s1 ///
s445 respeak debatelevel ledebate, nohr cluster(name) strata(state) efron schoenfeld(sch*) scaledsch(sca*)
stphtest, rank detail
drop sch1-sca18

*with corrections for prop. hazards used in Table \ref{4}
stcox leaderposition chairman committee absnom party reelection ///
number_o senior rawcscor amendcosponsor busy office hr1904 s1 ///
s445 respeak debatelevel ledebate hr1904t s1t s445t debatet, nohr cluster(name) strata(state) efron

*showing hazard coefficients
stcox leaderposition chairman committee absnom party reelection ///
number_o senior rawcscor amendcosponsor busy office hr1904 s1 ///
s445 respeak debatelevel ledebate hr1904t s1t s445t debatet, cluster(name) strata(state) efron

margins, dydx(leaderposition) at(debatelevel=(0(1)1))

*****************Table 5
*dichotomize by level of debate
*heavily debated where debatelevel==1
*note that debatelevel is not included as a separate variable nor is it interacted with anything
*s1 is dropped - there are no s1 amendments that qualify as heavily debated, therefore hr1904 is omitted as the reference category
stcox leaderposition chairman committee absnom party reelection ///
number_o senior rawcscor amendcosponsor busy office hr1904 s1 ///
s445 respeak if debatelevel==1,  nohr cluster(name) strata(state) efron schoenfeld(sch*) scaledsch(sca*)
stphtest, rank detail
drop sch1-sca16

*with fixes for proporational hazards
stcox leaderposition chairman committee absnom party reelection ///
number_o senior rawcscor amendcosponsor busy office hr1904 s1 ///
s445 respeak s445t if debatelevel==1,  nohr cluster(name) strata(state) efron

*same model as above with hazard ratios

stcox leaderposition chairman committee absnom party reelection ///
number_o senior rawcscor amendcosponsor busy office  hr1904 s1 ///
s445 respeak s445t if debatelevel==1,   cluster(name) strata(state) efron

************************************************
*not heavily debated where debatelevel==0
*s445 is dropped - there are no s1 amendments that qualify as heavily debated, therefore s14 is omitted as the reference category
stcox leaderposition chairman committee absnom party reelection ///
number_o senior rawcscor amendcosponsor busy office hr1904 s1 ///
s445 respeak if debatelevel==0,  nohr cluster(name) strata(state) efron schoenfeld(sch*) scaledsch(sca*)
stphtest, rank detail
drop sch1-sca16

*with fixes for prop. hazards
stcox leaderposition chairman committee absnom party reelection ///
number_o senior rawcscor amendcosponsor busy office hr1904 s1 ///
s445 respeak hr1904t s1t if debatelevel==0,  nohr cluster(name) strata(state) efron

*same model as above with hazard ratios
stcox leaderposition chairman committee absnom party reelection ///
number_o senior rawcscor amendcosponsor busy office  hr1904 s1 ///
s445 respeak hr1904t s1t if debatelevel==0, cluster(name) strata(state) efron



*For Figure 1 please see procedure reported on page 41. Using this procedure, permutation coefficients were generated for each of the four models
*these are saved in separate datasets available in the replication files. Note that the generation of permutation coefficients will produce slightly
*different coefficents than those in our data
*see "permutation coefficients for figure 1" do file for code on using the permutation coefficients in each of the datasets to generate the graphs in 
*figure 1

